#include "delegate.h"
#include <stdlib.h>

void delegate_create(Delegate** delegate, void* (*function) (void* args), void** args)
{
    (*delegate) = (Delegate*) malloc(sizeof(Delegate));
    delegate_initialize((*delegate),function,args);
}

void delegate_initialize(Delegate* delegate, void* (*function) (void* args), void** args)
{
    delegate->function = function;
    delegate->args = *args;
}

void delegate_clear(Delegate* delegate)
{
    free(delegate->args);
    delegate->args = NULL;
    delegate->function = NULL;
}

void delegate_destroy(Delegate** delegate)
{
    delegate_clear((*delegate));
    free((*delegate));
}
    
